package com.drop.entity;

import javax.persistence.*;

import static javax.persistence.GenerationType.IDENTITY;

/**
 * Cart entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "cart", catalog = "feature_mall")
public class Cart implements java.io.Serializable {

	// Fields

	private Integer cartId;
	private Goods goods;
	private User user;
	private Integer quantity;
	private String addTime;
	private String totalPrice;

	@Override
	public String toString() {
		return "Cart{" +
				"cartId=" + cartId +
				", quantity=" + quantity +
				", addTime='" + addTime + '\'' +
				", totalPrice='" + totalPrice + '\'' +
				'}';
	}

// Constructors

	/** default constructor */
	public Cart() {
	}

	/** full constructor */
	public Cart(Goods goods, User user, Integer quantity, String addTime, String totalPrice) {
		this.goods = goods;
		this.user = user;
		this.quantity = quantity;
		this.addTime = addTime;
		this.totalPrice = totalPrice;
	}

	// Property accessors
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "cartId", unique = true, nullable = false)
	public Integer getCartId() {
		return this.cartId;
	}

	public void setCartId(Integer cartId) {
		this.cartId = cartId;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "goodsId")
	public Goods getGoods() {
		return this.goods;
	}

	public void setGoods(Goods goods) {
		this.goods = goods;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "userId")
	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Column(name = "quantity")
	public Integer getQuantity() {
		return this.quantity;
	}

	public void setQuantity(Integer quantity) {
		this.quantity = quantity;
	}

	@Column(name = "addTime", length = 45)
	public String getAddTime() {
		return this.addTime;
	}

	public void setAddTime(String addTime) {
		this.addTime = addTime;
	}

	public String getTotalPrice(){
		return this.goods.getPrice()*this.quantity+"";
	}
	public void setTotalPrice(String totalPrice){
		this.totalPrice = totalPrice;
	}

}